﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DM_TOOLS.Tools.DBC.DBCTime
{
    public static class DBCTime
    {
        /// <summary>
        /// CSV 里是 "2025-09-24 18:10:43.788"，取 当天时间部分 转成秒。比如:"2025-09-24 18:10:43.788" → 65443.788
        /// </summary>
        /// <param name="ts"></param>
        /// <returns></returns>
        /// <exception cref="FormatException"></exception>
        public static double ParseTimestamp(this string? ts)
        {
            if (DateTime.TryParse(ts, out var dt))
            {
                // 只取当天时间部分
                return dt.TimeOfDay.TotalSeconds;
            }

            throw new FormatException($"无法解析 TimeStamp: {ts}");
        }
    }
}
